<template>
  <div class="wrapper" ref="wrapper">
  <div class="content">
  <slot></slot>
</div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: "Scroll",
  data() {
    return {
      scroll:null,
    };
  },
  props:{
        probeType:{
         type:Number,
          default:0
            },
         pullUpLoad:{
           type:Boolean,
           default:false
         }
        },

  mounted() {  //在组件挂载完毕后加载a
    this.scroll = new BScroll(this.$refs.wrapper,{
    click:true,
    pullUpLoad:this.pullUpLoad, //上拉加载更多
    probeType: this.probeType, //监听鼠标滚动事件
    },
    )
    this.scroll.on('scroll',(position)=>{  //监听鼠标滚动事件
      this.$emit('scroll',position);  //自定义方法，scroll组件向外传递一个名为scroll的方法，并向外传出position参数
    })
    this.scroll.on('pullingUp',()=>{ //实现上拉加载更多
      this.$emit('pullingUp')
    })
  },
  methods: {
    scrollTo(x,y,time=300){
      this.scroll&&this.scroll.scrollTo(x,y,time)   //在这里定义一个滚动位置的方法
    },
    finishPullUp(){
        this.scroll.finishPullUp()  //finishPullUp better-scroll内置函数，实现重复上拉加载更多
    },
    refresh(){
      this.scroll&&this.scroll.refresh()
  },
  getScrollY(){
    return this.scroll?this.scroll.Y:0    //判断this.scroll.y是否有值，有值返回scroll.y，无值返回0
  }
  }
}
</script>

<style  scoped></style>